version 14.1
set more off

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.IX OF WASEEM (2020) ROLE OF WITHHOLDING ...
***************************************************************************************************


/* TABLE */

#d				;
matrix 			input table=(1997,0,0,0,0,0,0,0,0,0,0,0\
							 1998,0,0,0,0,0,0,0,0,0,0,0\
							 1999,0,0,0,0,0,0,0,0,0,0,0\
							 2000,0,0,0,0,0,0,0,0,0,0,0\
							 2001,0,0,0,0,0,0,0,0,0,0,0\
							 2002,0,0,0,0,0,0,0,0,0,0,0\
							 2003,0,0,0,0,0,0,0,0,0,0,0\
							 2004,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* NET VAT REVENUE BY YEAR */

use 			"$project_data\CommodityWiseRevenue_1997_2004_Wide.dta", clear
foreach 		var in t1997 t1998 t1999 t2000 t2001 t2002 t2003 t2004 {
replace			`var'=-`var' if commodity=="Refund Amount"
}
local			i=1997
foreach 		var in t1997 t1998 t1999 t2000 t2001 t2002 t2003 t2004 {
egen			agrev_`i'=sum(`var')
local			i=`i'+1
}
keep			if _n<=8
keep			sr agrev*
reshape			long agrev_, i(srno) j(year)
duplicates		drop year, force
drop			srno
g				R=agrev_
replace			R=(agrev_/0.125)*0.15 if year==1997
replace			R=(agrev_/0.142)*0.15 if year==1998
tsset			year
g				Rl=L1.R
g				percentdel=round(((R-Rl)/Rl)*100,0.01)
local			i=1
local			j=2
forvalues		i=1/8 {
matrix			table[`i',`j']=R[`i']
matrix 			table[`i',`j'+1]=percentdel[`i']
local			i=`i'+1
}

/* NET VAT REVENUE BY YEAR */

use 			"$project_data\CommodityWiseRevenue_1997_2004_Wide.dta", clear
foreach 		var in t1997 t1998 t1999 t2000 t2001 t2002 t2003 t2004 {
replace			`var'=-`var' if commodity=="Refund Amount"
replace			`var'=0.4*`var' if comm=="POL PRODUCTS (INCLUDING PETROLEUM, LUBRICATING OILS)"
}
drop			if comm=="ELECTRICAL ENERGY"
drop			if comm=="NATURAL GAS"
local			i=1997
foreach 		var in t1997 t1998 t1999 t2000 t2001 t2002 t2003 t2004 {
egen			agrev_`i'=sum(`var')
local			i=`i'+1
}
keep			if _n<=8
keep			sr agrev*
reshape			long agrev_, i(srno) j(year)
duplicates		drop year, force
drop			srno
g				R=agrev_
replace			R=(agrev_/0.125)*0.15 if year==1997
replace			R=(agrev_/0.142)*0.15 if year==1998
tsset			year
g				Rl=L1.R
g				percentdel=round(((R-Rl)/Rl)*100,0.01)
local			i=1
local			j=4
forvalues		i=1/8 {
matrix			table[`i',`j']=R[`i']
matrix 			table[`i',`j'+1]=percentdel[`i']
local			i=`i'+1
}

/* VAT REVENUE GROWTH CAUSED BY THE REFORM */

use 			"$project_data\CommodityWiseRevenue_1997_2004_Wide.dta", clear
foreach 		var in t1997 t1998 t1999 t2000 t2001 t2002 t2003 t2004 {
replace			`var'=-`var' if commodity=="Refund Amount"
replace			`var'=0.7*`var' if comm=="POL PRODUCTS (INCLUDING PETROLEUM, LUBRICATING OILS)"
replace			`var'=0.33*`var' if comm=="ELECTRICAL ENERGY"
replace			`var'=0.66*`var' if comm=="NATURAL GAS"
}
local			i=1997
foreach 		var in t1997 t1998 t1999 t2000 t2001 t2002 t2003 t2004 {
egen			agrev_`i'=sum(`var')
local			i=`i'+1
}
keep			if _n<=8
keep			sr agrev*
reshape			long agrev_, i(srno) j(year)
duplicates		drop year, force
drop			srno
g				R=agrev_
replace			R=(agrev_/0.125)*0.15 if year==1997
replace			R=(agrev_/0.142)*0.15 if year==1998
tsset			year
g				Rl=L1.R
g				percentdel=round(((R-Rl)/Rl)*100,0.01)
local			i=1
local			j=6
forvalues		i=1/8 {
matrix			table[`i',`j']=R[`i']
matrix 			table[`i',`j'+1]=percentdel[`i']
local			i=`i'+1
}

/* FORMATTING TABLE */

svmat			table
keep			tab*
drop			table8-table12
g				c1=string(table1)
foreach			c in 2 4 6  {
g				c`c'=string(table`c',"%9.0fc")
}

foreach			c in 3 5 7  {
g				c`c'=string(table`c',"%9.2f")
}
g				s1="&"
g				s2="&"
g				s3="&&"
g				s4="&"
g				s5="&&"
g				s6="&"
g				l="\\"
browse 			c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 l
